package com.ghck.server.config.remote;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;

import com.ghck.message.service.EasemobService;
import com.ghck.message.service.JpushService;
import com.ghck.message.service.SmsSendService;
import com.ghck.shop.service.GoodsService;
import com.ghck.shop.service.OperateService;
import com.ghck.shop.service.OrderService;
import com.ghck.shop.service.SellerService;
import com.ghck.shop.service.ShoppingCartService;
import com.ghck.shop.service.StatisticsService;
import com.ghck.shop.service.UserAddressService;

@Configurable
public class HttpInvokerClientConfig {
	
	@Autowired
	private Environment env;
	
	private Logger log = LoggerFactory.getLogger(HttpInvokerClientConfig.class);
	

	@Bean(name="smsSendService")
	public HttpInvokerProxyFactoryBean smsSendService(){
		HttpInvokerProxyFactoryBean httpInvokerProxy = new HttpInvokerProxyFactoryBean();
		httpInvokerProxy.setServiceUrl(env.getProperty("ghck.remote.mc") +"/smsSendService");
		httpInvokerProxy.setServiceInterface(SmsSendService.class);
		return httpInvokerProxy;
	}
	
	@Bean(name="jpushService")
	public  HttpInvokerProxyFactoryBean userService(){
		HttpInvokerProxyFactoryBean httpInvokerProxy = new HttpInvokerProxyFactoryBean();
		log.info("env : {}",env);
		log.info("env.getProperty(ghck.remote.mc) {}",env.getProperty("ghck.remote.mc"));
		httpInvokerProxy.setServiceUrl(env.getProperty("ghck.remote.mc") +"/jpushService");
		httpInvokerProxy.setServiceInterface(JpushService.class);
		//httpInvokerProxy.setServiceUrl("222");
		return httpInvokerProxy;
	}
	
	@Bean(name="easemobService")
	public  HttpInvokerProxyFactoryBean easemobService(){
		HttpInvokerProxyFactoryBean httpInvokerProxy = new HttpInvokerProxyFactoryBean();
		httpInvokerProxy.setServiceUrl(env.getProperty("ghck.remote.mc") +"/easemobService");
		httpInvokerProxy.setServiceInterface(EasemobService.class);
		//httpInvokerProxy.setServiceUrl("222");
		return httpInvokerProxy;
	}
	
	@Bean(name="sellerService")
	public  HttpInvokerProxyFactoryBean sellerServiceBean(){
		HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
		bean.setServiceInterface(SellerService.class);
		bean.setServiceUrl(env.getProperty("ghck.remote.sellerService"));
		//bean.setServiceUrl("222");
		return bean;
	}
	
	
	@Bean(name="goodsService")
	public GoodsService goodsServiceBean(){
		HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
		bean.setServiceInterface(GoodsService.class);
		bean.setServiceUrl(env.getProperty("ghck.remote.goodsService"));
		//bean.setServiceUrl("222");
		bean.afterPropertiesSet();
		return (GoodsService) bean.getObject();
	}
	
	@Bean(name="operateService")
	public OperateService operateServiceBean(){
		HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
		bean.setServiceInterface(OperateService.class);
		bean.setServiceUrl(env.getProperty("ghck.remote.operateService"));
		bean.afterPropertiesSet();
		return (OperateService) bean.getObject();
	}
	@Bean(name="statisticsService")
	public StatisticsService statisticsServiceBean(){
		HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
		bean.setServiceInterface(StatisticsService.class);
		bean.setServiceUrl(env.getProperty("ghck.remote.statisticsService"));
		bean.afterPropertiesSet();
		return (StatisticsService) bean.getObject();
	}
	
	@Bean(name="orderService")
	public OrderService orderServiceBean(){
		HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
		bean.setServiceInterface(OrderService.class);
		bean.setServiceUrl(env.getProperty("ghck.remote.orderService"));
		bean.afterPropertiesSet();
		return (OrderService) bean.getObject();
	}
	
	@Bean(name="userAddressService")
	public UserAddressService userAddressServiceBean(){
		HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
		bean.setServiceInterface(UserAddressService.class);
		bean.setServiceUrl(env.getProperty("ghck.remote.userAddressService"));
		//bean.setServiceUrl("222");
		bean.afterPropertiesSet();
		return (UserAddressService) bean.getObject();
	}
	
	@Bean(name="shoppingCartService")
	public ShoppingCartService shoppingCartServiceBean(){
		HttpInvokerProxyFactoryBean bean = new HttpInvokerProxyFactoryBean();
		bean.setServiceInterface(ShoppingCartService.class);
		bean.setServiceUrl(env.getProperty("ghck.remote.shoppingCartService"));
		bean.afterPropertiesSet();
		return (ShoppingCartService) bean.getObject();
	}
	
	
	
	
}